<template>
    <div id="SearchView">
        <div class="searchViewHead">
            <span class="mui-icon mui-icon-back" @click="pushBack"></span>
            <i class="mui-icon mui-icon-search"></i>
            <input type="text" placeholder="商品名称、档口/..." v-model="value">
            <span @click="pushsearchresult">搜索</span>
        </div>
        <div class="searchViewContent">
            <ul>
                <li v-for="(item,key) in navlist" :key="key" @click="pushView(item,key)">
                    {{item.name}}
                </li>
            </ul>
            <router-view></router-view>
        </div>
    </div>
</template>
<script>
import { Toast } from "mint-ui";
export default {
  data() {
    return {
      value: "",
      navlist: [
        { name: "档口/品牌", path: "/SearchView/brand" },
        { name: "类目", path: "/SearchView/category" }
      ]
    };
  },
  methods: {
    pushBack() {
      this.$router.push({ path: "/home" });
    },
    pushView(item, key) {
      this.$store.state.displayMode = 1 - key;
      this.$router.push({ path: item.path });
    },
    pushsearchresult() {
      if (this.value.trim() == "") {
        Toast({
          message: "请输入关键字搜索",
          position: "bottom",
          duration: 2000
        });
      } else {
        this.$store.state.searchkeyword = this.value;
        console.log(this.$store.state.searchkeyword);
        this.value = "";
        if (this.$store.state.searchkeyword.search(this.value) != -1) {
          this.$router.push({ path: "/searchResult" });
        }
      }
    }
  }
};
</script>

<style lang="scss" scoped>
#SearchView {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: white;
  z-index: 999;
  .searchViewHead {
    position: fixed;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-end;
    width: 100%;
    height: 60px;
    background: #c6091b;

    padding-bottom: 10px;
    span {
      flex: 2;
      text-align: center;
      line-height: 40px;
    }
    input {
      flex: 8;
      margin: 0;
      padding-left: 40px;
    }
    i {
      position: absolute;
      left: 16%;
      top: 30%;
    }
  }
  .searchViewContent {
    width: 100%;
    height: 100%;
    margin-top: 60px;
    background: white;
    ul {
      display: flex;
      flex-direction: row;
      justify-content: space-around;
      height: 40px;
      line-height: 40px;
      background: #cccccc;
    }
  }
}
</style>

